<?php
/**
 * ErrorException
 * @copyright   Copyright(c) 2024-2034
 * @author      tianjie <527707665@qq.com>
 * @link        http://www.tinphp.com/
 * @version     4.1
 */

namespace tian\exception;

use tian\Exception;

class ErrorException extends Exception
{
    /**
     * 用于保存错误级别
     * @var integer
     */
    protected $severity;

    /**
     * 错误异常构造函数
     * @param integer $severity 错误级别
     * @param string $message 错误详细信息
     * @param string $file 出错文件路径
     * @param integer $line 出错行号
     * @param array $context 错误上下文，会包含错误触发处作用域内所有变量的数组
     */
    public function __construct($severity, $message, $file, int $line, array $context = [])
    {
        $this->severity = $severity;
        $this->message = $message;
        $this->file = $file;
        $this->line = $line;
        $this->code = 0;

        empty($context) || $this->setData('Error Context', $context);

        parent::__construct($message, $this->code);
    }

    /**
     * 获取错误级别
     * @return int
     */
    final public function getSeverity(): int
    {
        return $this->severity;
    }
}
